package com.damacheng009.future.alarm.crawler;

import java.util.ArrayList;
import java.util.List;

import com.damacheng009.future.alarm.vo.KLineVo;

import cn.hutool.core.util.StrUtil;

public class TencentStockDayCrawler extends BaseCrawler {

	@Override
	public List<KLineVo> getKLines(String code) {
		this.url = "http://data.gtimg.cn/flashdata/hushen/latest/daily/" + code + ".js";
		String str = wget(null);
		
		String[] lines = StrUtil.split(str, "\n");
		List<KLineVo> retList = new ArrayList<KLineVo>();
		
		for (int i = 2; i < lines.length; ++i) {
			String line = lines[i];
			String[] tmp = StrUtil.split(line, " ");
			KLineVo vo = new KLineVo();
			vo.setC(tmp[2]);
			vo.setH(tmp[3]);
			vo.setL(tmp[4]);
			vo.setO(tmp[1]);
			vo.setV(tmp[5]);
			vo.setD("20" + tmp[0].substring(0, 2) + "-" + tmp[0].substring(2, 4) + "-" + tmp[0].substring(4, 6));
			
			retList.add(vo);
		}

		return retList;
	}

	@Override
	protected String clean(String originString) {
		String tmp = StrUtil.replace(originString, "\";", "");
		tmp = StrUtil.replace(tmp, "\\n\\", "");
		return StrUtil.trim(tmp);
	}

}
